# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.http import JsonResponse
from .models import Customer, Product, Order, Equipment, Employee, WorkOrder

def dashboard(request):
    """仪表板视图"""
    context = {
        'total_customers': Customer.objects.count(),
        'total_products': Product.objects.count(),
        'total_orders': Order.objects.count(),
        'total_equipment': Equipment.objects.count(),
        'total_employees': Employee.objects.count(),
        'active_work_orders': WorkOrder.objects.filter(status__in=['created', 'assigned', 'in_progress']).count(),
    }
    return render(request, 'simple_mes/dashboard.html', context)

def api_stats(request):
    """API统计数据"""
    data = {
        'customers': Customer.objects.count(),
        'products': Product.objects.count(),
        'orders': Order.objects.count(),
        'equipment': Equipment.objects.count(),
        'employees': Employee.objects.count(),
        'work_orders': WorkOrder.objects.count(),
    }
    return JsonResponse(data) 